
package com.ffcs.crmd.tsp.admin.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.utils.bean.BeanUtils;
import com.ffcs.crmd.platform.core.ddd.facade.impl.AbstractCrmDomFacade;
import com.ffcs.crmd.tsp.admin.api.dto.ClusterDTO;
import com.ffcs.crmd.tsp.admin.api.facade.IClusterFacade;
import com.ffcs.crmd.tsp.admin.entity.Cluster;
import com.ffcs.crmd.tsp.admin.service.IClusterService;

@Service("clusterFacade")
public class ClusterFacadeImpl extends AbstractCrmDomFacade implements IClusterFacade {
   	
   	@Autowired
	private IClusterService clusterService;
	   
	@Override
    public void save(ClusterDTO clusterDto) throws Exception {
        Cluster cluster = new Cluster();
        BeanUtils.applyIf(cluster, clusterDto, false);
        clusterService.saveCluster(cluster);
    }
    
    @Override
    public void remove(ClusterDTO clusterDto) throws Exception {
        Cluster cluster = new Cluster();
        BeanUtils.applyIf(cluster, clusterDto, false);
        clusterService.deleteCluster(cluster);
    }
    
    @Override
    public void remove(List<ClusterDTO> clusterDtoList) throws Exception {
        List<Cluster> clusterList = BeanUtils.copyList(clusterDtoList, Cluster.class);
        clusterService.deleteCluster(clusterList);
    }
    
    @Override
    public void update(ClusterDTO clusterDto) throws Exception {
        Cluster cluster = new Cluster();
        BeanUtils.applyIf(cluster, clusterDto, false);
        clusterService.updateCluster(cluster);
    }
    
    private PageInfo<ClusterDTO> copyPageInfo(PageInfo<Cluster> pageInfo) throws Exception{
        PageInfo<ClusterDTO> pageInfoDto = new PageInfo<ClusterDTO>();
        BeanUtils.applyIf(pageInfoDto, pageInfo, false);
        pageInfoDto.setList(BeanUtils.copyList(pageInfo.getList(), ClusterDTO.class));
        return pageInfoDto;
    }

    /**
     * 功能说明:
     * 
     * @return
     * @throws Exception
     */
    @Override
    public List<ClusterDTO> query() throws Exception {
        List<Cluster> sliceList = clusterService.query();
        return BeanUtils.copyList(sliceList, ClusterDTO.class);
    }

    /**
     * 功能说明:
     * 
     * @param name
     * @return
     * @throws Exception
     */
    @Override
    public List<ClusterDTO> query(String name) throws Exception {
        List<Cluster> sliceList = clusterService.query(name);
        return BeanUtils.copyList(sliceList, ClusterDTO.class);
    }

    /**
     * 功能说明:
     * 
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<ClusterDTO> queryPage(int pageNumber, int pageSize) throws Exception {
        PageInfo<Cluster> pageInfo = clusterService.queryPage(pageNumber, pageSize);
        return copyPageInfo(pageInfo);
    }

    /**
     * 功能说明:
     * 
     * @param name
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<ClusterDTO> queryPage(String name, int pageNumber, int pageSize) throws Exception {
        PageInfo<Cluster> pageInfo = clusterService.queryPage(name, pageNumber, pageSize);
        return copyPageInfo(pageInfo);
    }
}
